package com.itrh.auth.service.impl;

import com.itrh.auth.domain.Menu;
import com.itrh.auth.mapper.MenuMapper;
import com.itrh.auth.service.IMenuService;
import com.itrh.base.service.impl.BaseServiceImpl;
import com.itrh.org.util.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author XHU_WHY
 * @since 2024-04-07
 */
@Service
public class MenuServiceImpl extends BaseServiceImpl<Menu> implements IMenuService {
    @Resource
    private MenuMapper menuMapper;
    @Override
    public Result saveOrUpdate(Menu menu) {
        try {
            if (menu.getId() == null) {
                menuMapper.insert(menu);
            } else {
                menuMapper.update(menu);
            }
            return Result.success();
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("保存失败");
        }
    }

    @Override
    public Result getTree() {
        List<Menu> menus = menuMapper.selectTree();
        return Result.success(menus);
    }
}
